<template>
	<view>
		<el-tabs v-model="activeName" @tab-click="handleClick" style="margin: 0 20px;">
		    <el-tab-pane label="基础设置" name="base" v-loading="loading">
				<view class="page-body" style="max-width: 800px;">
					<vk-data-form
						v-model="form1.data"
						:rules="form1.props.rules"
						:action="form1.props.action"
						:form-type="form1.props.formType"
						:columns='form1.props.columns'
						:loading.sync="form1.props.loading"
						label-width="140px"
						:show-cancel="false"
						submit-text="保存"
						@success="handleClick"
					></vk-data-form>
				</view>
			</el-tab-pane>
		    <el-tab-pane label="积分设置" name="score" v-loading="loading">
				<view class="page-body" style="max-width: 800px;">
					<vk-data-form
						v-model="form2.data"
						:rules="form2.props.rules"
						:action="form2.props.action"
						:form-type="form2.props.formType"
						:columns='form2.props.columns'
						:loading.sync="form2.props.loading"
						label-width="140px"
						:show-cancel="false"
						submit-text="保存"
						@success="handleClick"
					></vk-data-form>
				</view>
			</el-tab-pane>
		    <el-tab-pane label="缩略图设置" name="thumb" v-loading="loading">
				<view class="page-body" style="max-width: 800px;">
					<vk-data-form
						v-model="form5.data"
						:rules="form5.props.rules"
						:action="form5.props.action"
						:form-type="form5.props.formType"
						:columns='form5.props.columns'
						:loading.sync="form5.props.loading"
						label-width="140px"
						:show-cancel="false"
						submit-text="保存"
						@success="handleClick"
					></vk-data-form>
				</view>
			</el-tab-pane>
		    <el-tab-pane label="微信端配置" name="wx" v-loading="loading">
				<view class="page-body" style="max-width: 800px;">
					<vk-data-form
						v-model="formWx.data"
						:rules="formWx.props.rules"
						:action="formWx.props.action"
						:form-type="formWx.props.formType"
						:columns='formWx.props.columns'
						:loading.sync="formWx.props.loading"
						label-width="140px"
						:show-cancel="false"
						submit-text="保存"
						@success="handleClick"
					></vk-data-form>
				</view>
			</el-tab-pane>
		  </el-tabs>
	</view>
</template>

<script>
	var that;													// 当前页面对象
	var vk = uni.vk;									// vk实例
	var originalForms = {};						// 表单初始化数据
	
	export default {
		data() {
			return {
				loading: true,
				activeName: 'base',
				// 表单相关开始-----------------------------------------------------------
				form1: {
					// 表单请求数据，此处可以设置默认值
					data: {
						config_key: 'base_config',
					},
					// 表单属性
					props: {
						// 表单请求地址
						action:"admin/wechat/config/sys/edit",
						// 表单字段显示规则
						columns:[
							{ key: "name", title:"程序名称", type:"text" },
							{ key: "desc", title:"程序描述", type:"text" },
							{ key: "version", title:"程序版本", type:"text" },
							{ key: "logo", title:"LOGO", type:"file-select" },
							{ key: "image", title:"程序封面", type:"file-select" },
							{ key: "qrcode", title:"客服二维码", type:"file-select" },
							{ key: "qq", title:"联系QQ", type:"text" },
							{ key: "email", title:"联系邮箱", type:"text" }
						],
						// 表单验证规则
						rules: {
				
						},
						// add 代表添加 update 代表修改
						formType:'',
						// 是否显示表单1 的弹窗
						show: false,
						// 表单是否在请求中
						loading:false
					}
				},
				form2: {
					// 表单请求数据，此处可以设置默认值
					data: {
						config_key: 'score_config',
						invite_score: 0,
						invite_num: 0,
						video_score: 0,
						video_num: 0,
						sign_score: 0,
						register_score: 0
					},
					// 表单属性
					props: {
						// 表单请求地址
						action:"admin/wechat/config/sys/edit",
						// 表单字段显示规则
						columns:[
							{ key: "name", title:"积分名称", type:"text" },
							{ key: "icon", title:"积分图标", type:"file-select" },
							{ key: "invite_score", title:"邀请好友获得积分", type:"number" },
							{ key: "invite_num", title:"每日次数", type:"number", tips: "邀请好友每日次数限制，填写0为不限制"},
							{ key: "video_score", title:"激励视频获得积分", type:"number" },
							{ key: "video_num", title:"每日次数", type:"number", tips: "激励视频每日次数限制，填写0为不限制，请注意这里的限制次数和作品视频次数不相关，一般设置5比较合理"},
							{ key: "sign_score", title:"签到积分", type:"number", tips: "签到赠送积分，设置0为关闭" },
							{ key: "register_score", title:"注册积分", type:"number", tips: "注册赠送积分，设置0为关闭" },
						],
						// 表单验证规则
						rules: {
				
						},
						// add 代表添加 update 代表修改
						formType:'',
						// 是否显示表单1 的弹窗
						show: false,
						// 表单是否在请求中
						loading:false
					}
				},
				form5: {
					// 表单请求数据，此处可以设置默认值
					data: {
						config_key: 'thumb_config',
						cover_flag: 0,
						avatar_flag: 0,
						look_flag: 0,
						special_flag: 0
					},
					// 表单属性
					props: {
						// 表单请求地址
						action:"admin/wechat/config/sys/edit",
						// 表单字段显示规则
						columns:[
							{ key:"cover_flag", title:"【壁纸】", type:"switch", activeValue:1, inactiveValue:0, tips: '开启后【壁纸列表】将使用阿里云OSS缩略图，请注意这并非免费，具体费用请查看阿里云OSS'},
							{ key: "cover_style", showRule: "cover_flag=1", title:"规则", tips: '具体规则查看阿里云OSS，不知道的可以设置为：?x-oss-process=image/resize,m_lfit,w_226/quality,Q_90', type:"text" },
							{ key:"avatar_flag", title:"【头像】", type:"switch", activeValue:1, inactiveValue:0, tips: '开启后【头像列表】将使用阿里云OSS缩略图，请注意这并非免费，具体费用请查看阿里云OSS'},
							{ key: "avatar_style", showRule: "avatar_flag=1", title:"规则", tips: '具体规则查看阿里云OSS，不知道的可以设置为：?x-oss-process=image/resize,m_lfit,w_226/quality,Q_90', type:"text" },
							{ key:"look_flag", title:"【表情包】", type:"switch", activeValue:1, inactiveValue:0, tips: '开启后【表情包列表】将使用阿里云OSS缩略图，请注意这并非免费，具体费用请查看阿里云OSS'},
							{ key: "look_style", showRule: "look_flag=1", title:"规则", tips: '具体规则查看阿里云OSS，不知道的可以设置为：?x-oss-process=image/resize,m_lfit,w_350/quality,Q_90', type:"text" },
							{ key:"special_flag", title:"【专题】", type:"switch", activeValue:1, inactiveValue:0, tips: '开启后【专题列表】将使用阿里云OSS缩略图，请注意这并非免费，具体费用请查看阿里云OSS'},
							{ key: "special_style", showRule: "special_flag=1", title:"规则", tips: '具体规则查看阿里云OSS，不知道的可以设置为：?x-oss-process=image/resize,m_lfit,w_350/quality,Q_90', type:"text" },
						],
						// 表单验证规则
						rules: {
				
						},
						// add 代表添加 update 代表修改
						formType:'',
						// 是否显示表单1 的弹窗
						show: false,
						// 表单是否在请求中
						loading:false
					}
				},
				formWx: {
					// 表单请求数据，此处可以设置默认值
					data: {
						config_key: 'wx_config',
						down_flag: 0,
						avatar_flag: 0,
						look_flag: 0,
						downs_flag: 0,
						bill_cost: 0
					},
					// 表单属性
					props: {
						// 表单请求地址
						action:"admin/wechat/config/sys/edit",
						// 表单字段显示规则
						columns:[
							{ key: "verify", title:"过审开关", type:"switch", activeValue:true, inactiveValue:false, tips: "开启后将不显示开启过审按钮的所有内容" },
							{ key: "bill_cost", title:"提现手续费", type:"number", tips: "填写0不限制，0.2表示提现将扣除20%手续费，扣除和手续费尽量不要同时开启" },
							{ key: "banner_id", title:"banner广告", type:"text" },
							{ key: "videos_id", title:"激励视频广告", type:"text" },
							{ key: "down_flag", title:"壁纸下载", type:"radio", optionType: 'button', size: "mini",
								data:[
									{ value: 0, label: "免费" },
									{ value: 1, label: "积分" },
									{ value: 2, label: "广告" }
								]
							},
							{ key: "down_score", showRule: "down_flag=1 || down_flag=2", title:"壁纸下载积分", type:"number", tips: "除免费外，请配置此项，广告次数使用完之后会根据此项进行积分下载" },
							{ key: "avatar_flag", title:"头像下载", type:"radio", optionType: 'button', size: "mini",
								data:[
									{ value: 0, label: "免费" },
									{ value: 1, label: "积分" },
									{ value: 2, label: "广告" }
								]
							},
							{ key: "avatar_score", showRule: "avatar_flag=1 || avatar_flag=2", title:"头像下载积分", type:"number", tips: "除免费外，请配置此项，广告次数使用完之后会根据此项进行积分下载" },
							{ key: "look_flag", title:"表情包下载", type:"radio", optionType: 'button', size: "mini",
								data:[
									{ value: 0, label: "免费" },
									{ value: 1, label: "积分" },
									{ value: 2, label: "广告" }
								]
							},
							{ key: "look_score", showRule: "look_flag=1 || look_flag=2", title:"表情下载积分", type:"number", tips: "除免费外，请配置此项，广告次数使用完之后会根据此项进行积分下载" },
							{ key: "downs_flag", title:"动态壁纸下载", type:"radio", optionType: 'button', size: "mini",
								data:[
									{ value: 0, label: "免费" },
									{ value: 1, label: "积分" },
									{ value: 2, label: "广告" }
								]
							},
							{ key: "downs_score", showRule: "downs_flag=1 || downs_flag=2", title:"动态壁纸下载积分", type:"number", tips: "除免费外，请配置此项，广告次数使用完之后会根据此项进行积分下载" },
						],
						// 表单验证规则
						rules: {
							
						},
						// add 代表添加 update 代表修改
						formType:'',
						// 是否显示表单1 的弹窗
						show: false,
						// 表单是否在请求中
						loading:false
					}
				}
				// 表单相关结束-----------------------------------------------------------
				
			}
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this
			vk = that.vk;
			that.options = options;
			that.init(options);
		},
		methods: {
			async init(options) {
				that = this
				let data = await vk.callFunction({
					url: 'admin/wechat/config/sys/getKeys',
					data:{
						config_key: 'base_config'
					}
				});
				if(data.info) that.form1.data = data.info
				that.loading = false
			},
			async handleClick() {
				that = this
				that.loading = true
				if(that.activeName === "base"){
					let data = await vk.callFunction({
						url: 'admin/wechat/config/sys/getKeys',
						data:{
							config_key: 'base_config'
						}
					});
					if(data.info) that.form1.data = data.info
				}else if(that.activeName === "score"){
					let data = await vk.callFunction({
						url: 'admin/wechat/config/sys/getKeys',
						data:{
							config_key: 'score_config'
						}
					});
					if(data.info) that.form2.data = data.info
				}else if(that.activeName === "thumb"){
					let data = await vk.callFunction({
						url: 'admin/wechat/config/sys/getKeys',
						data:{
							config_key: 'thumb_config'
						}
					});
					if(data.info) that.form5.data = data.info
				}else if(that.activeName === "wx"){
					let data = await vk.callFunction({
						url: 'admin/wechat/config/sys/getKeys',
						data:{
							config_key: 'wx_config'
						}
					});
					if(data.info) that.formWx.data = data.info
				}
				that.loading = false
			},
		}
	}
</script>

<style>

</style>
